/*********************************************************************
	filename:	DaterGroupMessageCreator.cpp
	created:	22/5/2012
	author:		4Ys
	
	purpose:	Implements class for Group Message Creator
*********************************************************************/
#include "DaterGroupMessageCreator.h"
#include "DaterCommon.h"
#include "DaterUserManager.h"

#include <strstream>

namespace Dater
{
	/*
		std::string getGroupCreateMessage(Group* _group);
		std::string getGroupAddMemberMessage(Group* _group, int memberID);
		std::string getGroupAskMemberMessage(Group* _group, int accept);
		std::string getGroupViewMessage(Group* _group);
		std::string getGroupJoinMessage(Group* _group, std::string reason);
		std::string getGroupAskCreatorMessage(Group* _group, int accept, int memberID);
		std::string getGroupAddEventMessage(Group* _group, int eventID);
		std::string getGroupAskEventMessage(int accept, Group* _group, int gEventID, Event* _event)
		std::string getGroupDeleteMemberMessage(Group* _group, int memberID);
		std::string getGroupList();
		std::string getAllGroupList(std::string keyword);
	*/

	std::string GroupMessageCreator::getGroupCreateMessage(std::string groupName, std::string type, 
		std::string description, Time createTime)
	{
		//3 \b 0 \b groupName
		std::string result = "3\b0\b" + groupName + "\b" + type + "\b" + description + "\b" + timeToString(createTime);

		return result;
	}

	std::string GroupMessageCreator::getGroupAddMemberMessage(Group* _group, int memberID)
	{
		//3 \b 1 \b groupID \b memberID
		std::string re, gID, mID;
		std::strstream str;
		str.clear();

		str << _group->getGid();
		str >> gID;
		str.clear();
		str << memberID;
		str >> mID;
		str.clear();

		re = "3\b1\b" + gID + "\b" + mID;
		return re;
	}

	std::string GroupMessageCreator::getGroupAskMemberMessage(Group* _group, int accept)
	{
		//3 \b 2 \b Accept(1/0) \b groupID \b creatorID
		std::string re, acc, gID, cID;
		std::strstream str;
		str.clear();

		str << _group->getGid();
		str >> gID;
		str.clear();
		str << _group->getCreatorID();
		str >> cID;
		str.clear();
		str << accept;
		str >> acc;
		str.clear();

		re = "3\b2\b" + acc + "\b" + gID + "\b" + cID;
		return re;
	}

	std::string GroupMessageCreator::getGroupViewMessage(int userID)
	{
		//3 \b 3 \b groupID
		char result[20];
		sprintf_s(result, "3\b3\b%d", userID);
		return result;
	}

	std::string GroupMessageCreator::getGroupJoinMessage(int groupID, std::string reason)
	{
		//3 \b 4 \b groupID \b reason
		std::string re, gID;
		std::strstream str;
		str.clear();

		str << groupID;
		str >> gID;
		str.clear();

		re = "3\b4\b" + gID + "\b" + reason;
		return re;
	}

	std::string GroupMessageCreator::getGroupAskJoinMessage(int groupID, int applicantID, bool accept)
	{
		std::string re, gID, aID;
		std::strstream str;
		str.clear();

		str << groupID;
		str >> gID;
		str.clear();
		str << applicantID;
		str >> aID;
		str.clear();

		re = "3\b5\b" + gID + "\b" + aID + "\b";
		if(accept)
		{
			re += "1";
		}else
		{
			re += "2";
		}
		return re;
	}

	std::string GroupMessageCreator::getGroupPublishEventMessage(int publisherID, int groupID, const std::string& groupName,
			const std::string& groupDescription, const Time& startTime, const Time& finishTime, const Time& createTime)
	{
		//3 \b 6 \b groupID \b eventID
		char result[400];
		sprintf_s(result,"3\b6\b%d\b%d\b%s\b%s\b%s\b%s\b%s", publisherID, groupID, groupName.c_str(), groupDescription.c_str(),
			timeToString(startTime).c_str(), timeToString(finishTime).c_str(), timeToString(createTime).c_str());

		std::string result_str(result);
		return result_str;
	}

	std::string GroupMessageCreator::getGroupDeleteMemberMessage(Group* _group, int memberID)
	{
		//3 \b 8 \b groupID \b memberID
		std::string re, gID, mID;
		std::strstream str;
		str.clear();

		str << _group->getGid();
		str >> gID;
		str.clear();
		str << memberID;
		str >> mID;
		str.clear();

		re = "3\b8\b" + gID + "\b" + mID;
		return re;
	}

	std::string GroupMessageCreator::getGroupList()
	{
		//3\b9
		std::string re;
		re = "3\b9";
		return re;
	}

	std::string GroupMessageCreator::getAllGroupList(std::string keyword)
	{
		//3 \b 10 \b keyword
		std::string re;
		re = "3\b10\b" + keyword;
		return re;
	}

	std::string GroupMessageCreator::getGroupResponseToEventMessage(int groupEventID, int userID, bool isAccept)
	{
		std::string result, groupEventID_s, userID_s;
		std::strstream str;
		str.clear();
		
		str << groupEventID;
		str >> groupEventID_s;
		str.clear();
		str << userID;
		str >> userID_s;
		str.clear();

		result = "3\b7\b";

		result += groupEventID_s + "\b" + userID_s + "\b";

		if(isAccept)
		{
			result += "1\b";
		}else
		{
			result += "2\b";
		}
		
		return result;
	}

	std::string GroupMessageCreator::getGroupSearchMessage(std::string name)
	{
		std::string result;
		result = "3\b11\b" + name;
		return result;
	}

}